import 'package:flutter/material.dart';
import 'package:Lter/style/theme.dart';
import 'package:Lter/util/screen.dart';
import 'package:Lter/util/toast.dart';
import 'package:Lter/model/app.dart';
import 'package:package_info/package_info.dart';

import 'dart:ui' as ui;

class NavSettingsScreen extends StatefulWidget {
  NavSettingsScreen({Key key}) : super(key: key);

  @override
  createState() => _NavSettingsScreenState();
}

class _NavSettingsScreenState extends State<NavSettingsScreen> {
  String mVersion = "";

  @override
  void initState() {
    super.initState();
    PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
      setState(() {
        mVersion = packageInfo.version;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    AppInherited app = AppContainer.of(context).app;

    return Scaffold(
      appBar: AppBar(
        title: Text('My Setting'),
      ),
      body: ListView(
        children: <Widget>[
          _buildHeader(),
          //_buildOnTapItem(Icons.favorite, '我的关注', _isDeving),
          //_buildOnTapItem(Icons.chat, '我的线索', _isDeving),
          _buildItem(Icons.phone_iphone, 'APP Version', mVersion),
          _buildItem(Icons.fingerprint, 'User Level',
              app.mUser.level == 1 ? "standard" : "super"),
          _buildItem(Icons.access_time, 'Reg Time', app.mUser.regtime),
        ],
      ),
    );
  }

  _isDeving() {
    Toast.show('This function is under development.');
  }

  Widget _buildItem(IconData iconData, String leftText, String rightText) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 10),
      width: Screen.width,
      padding: EdgeInsets.symmetric(vertical: 15),
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(color: AppTheme.lightGrey, width: 0.5))),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Row(
            children: <Widget>[
              Icon(iconData),
              SizedBox(
                width: 20,
              ),
              Text(
                leftText,
                style: TextStyle(fontSize: 16),
              )
            ],
          ),
          Text(
            rightText + "\t\t",
            style: TextStyle(fontSize: 16),
          )
        ],
      ),
    );
  }

  Widget _buildOnTapItem(IconData iconData, String leftText, onTap) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: 10),
        width: Screen.width,
        padding: EdgeInsets.symmetric(vertical: 15),
        decoration: BoxDecoration(
            border: Border(
                bottom: BorderSide(color: AppTheme.lightGrey, width: 0.5))),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Row(
              children: <Widget>[
                Icon(iconData),
                SizedBox(
                  width: 20,
                ),
                Text(
                  leftText,
                  style: TextStyle(fontSize: 16),
                )
              ],
            ),
            Icon(Icons.keyboard_arrow_right)
          ],
        ),
      ),
    );
  }

  Widget _buildHeader() {
    AppInherited app = AppContainer.of(context).app;

    double width = Screen.width;
    double height = Screen.height / 3;
    return Container(
      width: width,
      height: height,
      child: Stack(
        children: <Widget>[
          Opacity(
            opacity: 0.7,
            child: Container(
                color: Colors.black, width: Screen.width, height: height),
          ),
          BackdropFilter(
            filter: ui.ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
            child: Container(
                width: Screen.width,
                height: height,
                color: Colors.blue,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    CircleAvatar(
                      backgroundImage: AssetImage('assets/account.png'),
                      backgroundColor: Colors.white,
                      radius: 50.0,
                    ),
                    SizedBox(
                      height: 10,
                    ),
                    Text(app.mUser.username,
                        style: TextStyle(
                          fontSize: 18,
                          fontWeight: FontWeight.bold,
                          color: AppTheme.white,
                        ))
                  ],
                )),
          ),
        ],
      ),
    );
  }
}
